// Colorizer.v 
//
// Description:
// ------------ 
// The colorizer  module takes two-bit outputs, that indicate “transparent”
// or one of 3 opaque colors,  from the icon module and combines these two
// pixel steams into an 8-bit, 256-color output. The RojoBot icon will
// appear in the foreground in front of the world background.
//
//
// Input(s) :
// clk, video_on, world_pixel, icon
// Output(s):
// 
//
// Copyright Jabeer Ahmed and Caleb Mathisen, 2014
// 
// Created By:      Caleb Mathisen
// Author(s) :      Jabeer Ahmed, Caleb Mathisen
// Last Modified:   1/19/2014
//
// Revision History:
// Jan. 29 - CM
// Jan. 30 - JA
// Jan. 31 - JA
// 
// =============
// Description 
// =============
// The module is responsible for taking world map pixel values from BotSIM 
// module and the icon pixel values from the Icon modue and returning 
// 8-bit RGB pixel values to the output port. The pixel bit format is shown
// below.
//
//                      | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
//  color bits format : ---------------------------------   
//                      | R | R | R | G | G | G | B | B |
// 
//
// =============
// Inputs
// =============
//  * world_pixel   - 2-bit pixel value from the world map. (see below)
//  * icon          - 2-bit pixel value from the icon       (see below)
//                  - where, bits   : 00 = transparency
//                                  : 01 = color 1
//                                  : 10 = color 2
//                                  : 11 = color 3
//  
// 
// 
///////////////////////////////////////////////////////////////////////////

module Colorizer (

    input               clk,                    // 25 MHz clock
    input               video_on,               // Video on signal (from dtg)
    input       [1:0]   world_pixel,            // World pixel (extern: BotSIM)
    input       [1:0]   icon,                   // Icon pixel (from iconizer)

    output reg  [2:0]   red   = 3'b0,           // VGA port out
    output reg  [2:0]   green = 3'b0,           // VGA port out
    output reg  [1:0]   blue  = 2'b0            // VGA port out
);
    
    //                           8'brrrg_ggbb;      
    localparam BackGround  = 8'b11111111; // white
    localparam BlackLine   = 8'b00000000; // black
    localparam Obstruction = 8'b00011100; // green
    localparam IconColor_1 = 8'b00000011; // red
    localparam IconColor_2 = 8'b11100000; // black (Caleb)
    localparam IconColor_3 = 8'b11111100; // white (Caleb)

    wire use_icon, use_world;

    assign use_icon  = icon  > 2'b00;
//  assign use_world = world_pixel > 2'b00;

    always @(posedge clk) begin
        if (video_on) begin 

            if (use_icon) begin
                case (icon) 
                    2'b00 : {red, green, blue} <= 8'b11111111;              
                    2'b01 : {red, green, blue} <= IconColor_1; 
                    2'b10 : {red, green, blue} <= IconColor_2;
                    2'b11 : {red, green, blue} <= IconColor_3;
                endcase
            end     
            else begin 
                case (world_pixel) 
                    2'b00 : {red, green, blue} <= 8'b11111111;
                    2'b01 : {red, green, blue} <= 8'b00000000;
                    2'b10 : {red, green, blue} <= 8'b11100000;
                    2'b11 : {red, green, blue} <= 8'b11111111;
                endcase
            end
        end
        else 
            {red, green, blue} <= 8'b00000000;

    end
endmodule